﻿<?php
class myphp{
	function table($table=""){
		$this->pdo = new PDO("mysql:host=localhost;dbname=test","root","root");
		$this->table=$table;
		return $this;
	}
	function select($filed="", $kv=""){
			if($kv==""){
				$sql="select $filed from $this->table";
			}else{
				$sql="select $filed from $this->table where $kv";	
			}
			$this->res=$this->pdo->query($sql);
			
			return $this;
	}
	function insert($filed="", $v=""){

			$sql="insert into $this->table($filed) values ($v)";	
			
			$this->pdo->exec($sql);
			
			return $this;
	}
	function delete($kv){
		$sql="delete from $this->table where $kv ";
		$this->pdo->exec($sql);
		return $this;
	}
	function assign($k="",$v="",$file=null){
		$file==null?$file="app/index/content.html":$file;
		$file=file_get_contents($file);
		for($i=0;$i<count($k);$i++){
		$file=preg_replace("/\{$k[$i]\}/",$v[$i],$file);
		}
		file_put_contents("app/index/$this->gid.html",$file);
		header("location:app/index/$this->gid.html");
	}
	function assigns($file=null){
		$file==null?$file="app/index/content.html":$file;
		$file=file_get_contents($file);
		$file=str_replace("{id}",$this->gid,$file);
		file_put_contents("app/index/$this->gid.html",$file);
		header("location:app/index/$this->gid.html");
	}
	function display($k,$v){
		$model=$_GET['m'];
		$action=$_GET['a'];
		$file=file_get_contents("app/$model/$action.html");
		for($i=0;$i<count($k);$i++){
		$file=preg_replace("/\{$k[$i]\}/",$v[$i],$file);
		}
		echo $file;
	}
}
